﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Lbb.Common;
using System.Threading;
using System.Globalization;
using System.Collections.Generic;

namespace Lbb.Common.Test
{
    [TestClass]
    public class UtilityTest
    {
        [TestMethod]
        public void ToFriendlyTimeTest()
        {
            Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
            var now = DateTime.Now;

            var items = new Dictionary<string, DateTime>
            {
                {"10 seconds ago",now.AddSeconds(-10)},
                {"2 minutes ago",now.AddMinutes(-2)},
                {"1 hours ago",now.AddHours(-1)},
                {@"Today {1:hh\:mm\ tt}",now.AddHours(-6)},
                {@"Yesterday {1:hh\:mm\ tt}",now.AddDays(-1)},
                {@"{1:dddd hh\:mm\ tt}",now.AddDays(-2)},
                {@"{1:dd\ MMM\,\ hh:mm\ tt}",now.AddMonths(-1)},
                {@"{1:d/M/yy hh\:mm\ tt}",now.AddYears(-1)},
            };

            foreach (var item in items)
            {
                Assert.AreEqual(string.Format(item.Key, null, item.Value), item.Value.ToFriendlyTime());
            }
        }
    }
}
